
/*
 *  Copyright t lefering
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  These are the four essential freedoms with GNU GPL software:
 *  1: freedom to run the program, for any purpose
 *  2: freedom to study how the program works, and change it to make it do what you wish
 *  3: freedom to redistribute copies to help your Free Software friends
 *  4: freedom to distribute copies of your modified versions to your Free Software friends
 *   ,           ,
 *  /             \
 * ((__-^^-,-^^-__))
 * `-_---'  `---_-'
 *  `--|o`   'o|--'
 *      \  `  /
 *       ): :(
 *       :o_o:
 *        "-"
 *
 * program :== aux_section trans_section
 *
 * aux_section ::= auxiliaries %%
 *                 || %%
 *
 * auxiliaries ::= auxiliaries aux_def
 *                 || aux_def
 *
 * aux_def ::= name_def = reg_exp ;
 *             || %{ <anything> %}
 *
 * name_def ::= <name>
 *
 * reg_exp ::= <char_class>
 *             || <string>
 *             || <name>
 *             || reg_exp *
 *             || reg_exp | reg_exp
 *             || reg_exp  reg_exp
 *             || ( reg_exp )
 *
 * trans_section ::= translations
 *                   || <nothing>
 *
 * translations ::= translations translation
 *                  || translation
 *
 * translation ::= pattern action
 *                 || %{ <anything> %}
 *                 || %% <anything> <EOF>
 *
 * pattern ::= reg_exp / reg_exp
 *             || reg_exp
 */


%{

#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "main.h"

/* make sure extra debug code is available */
#define YYDEBUG 1

/*
 * When Using Bison-2.5.1
 * The variable error controls the verbosity of error messages.  The
 * use of the %error-verbose directive is deprecated in favor of
 * %define parse.error "verbose".
 */
#define YYERROR_VERBOSE 1


/* memory usage wrapping feature */
#ifndef YYFREE
# define YYFREE dp_free
#endif
#ifndef YYMALLOC
# define YYMALLOC dp_malloc
#endif
#ifndef YYREALLOC
# define YYREALLOC dp_realloc
#endif

/* forward decl. */
static void yyerror (const char *str);
static int yylex (void);

%}


%token TOKEN_NAME /* identifier */
%token TOKEN_CCLASS /* char-class */
%token TOKEN_STRING /* "string" */

%left ';'
%left '='
%left '/'
%left '|'
%left '(' TOKEN_NAME TOKEN_STRING TOKEN_CCLASS
%left TOKEN_CONCAT
%left '*'

%%



lexfile:
	  auxiliary_section translation_section
	| /* empty */
	;

auxiliary_section:
	  auxiliaries '%' '%'
	| '%' '%'
	;

auxiliaries:
	  auxiliaries auxiliary
	| auxiliary
	;

auxiliary:
	  namedef '=' regexp ';' { }
	| '%' '{' { }
	;

namedef:
	  TOKEN_NAME { }
	;

regexp:
	  TOKEN_CCLASS { }
	| TOKEN_STRING { }
	| TOKEN_NAME { }
	| regexp '*' { }
	| regexp '|' regexp { }
	| regexp regexp %prec TOKEN_CONCAT { }
	| '(' regexp ')' { }
	;

translation_section:
          translations { }
	| /* empty */ { }
	;

translations:
	  translations translation
	| llactr translation
	;

llactr:
	  /* empty */ { }
	;

translation:
	  pattern action { }
	| '%' '{' { }
	| '%' '%' { }
	;

action:
	  '{' { }
	;

pattern:
	  regexp '/' regexp { }
	| regexp
	;

%%

/* called by parser at error */
static void yyerror (const char *str)
{
  if(str){
    fputs(str,stderr);
    fflush(stderr);
    fflush(stdout);
  }
  return;
}

/* get next token */
static int yylex (void)
{
 return (0);
}

/* end. */
